package com.stylefeng.guns.modular.system.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.BuildingInfo;
import com.stylefeng.guns.modular.system.service.IBuildingInfoService;

/**
 * 楼栋信息控制器
 *
 * @author leequn
 * @Date 2018-08-02 23:38:47
 */
@Controller
@RequestMapping("/buildingInfo")
public class BuildingInfoController extends BaseController {

    private String PREFIX = "/system/buildingInfo/";

    @Autowired
    private IBuildingInfoService buildingInfoService;

    /**
     * 跳转到楼栋信息首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "buildingInfo.html";
    }

    /**
     * 跳转到添加楼栋信息
     */
    @RequestMapping("/buildingInfo_add")
    public String buildingInfoAdd() {
        return PREFIX + "buildingInfo_add.html";
    }

    /**
     * 跳转到修改楼栋信息
     */
    @RequestMapping("/buildingInfo_update/{buildingInfoId}")
    public String buildingInfoUpdate(@PathVariable Integer buildingInfoId, Model model) {
        BuildingInfo buildingInfo = buildingInfoService.selectById(buildingInfoId);
        model.addAttribute("item",buildingInfo);
        LogObjectHolder.me().set(buildingInfo);
        return PREFIX + "buildingInfo_edit.html";
    }

    /**
     * 获取楼栋信息列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return buildingInfoService.selectList(null);
    }

    /**
     * 新增楼栋信息
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(BuildingInfo buildingInfo) {
        buildingInfoService.insert(buildingInfo);
        return SUCCESS_TIP;
    }

    /**
     * 删除楼栋信息
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer buildingInfoId) {
        buildingInfoService.deleteById(buildingInfoId);
        return SUCCESS_TIP;
    }

    /**
     * 修改楼栋信息
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(BuildingInfo buildingInfo) {
        buildingInfoService.updateById(buildingInfo);
        return SUCCESS_TIP;
    }

    /**
     * 楼栋信息详情
     */
    @RequestMapping(value = "/detail/{buildingInfoId}")
    @ResponseBody
    public Object detail(@PathVariable("buildingInfoId") Integer buildingInfoId) {
        return buildingInfoService.selectById(buildingInfoId);
    }
}
